/*
 * @Author: xiaxia
 * @Description: 
 * @Date: 2024-07-03 17:24:18
 * @LastEditTime: 2024-07-08 15:20:43
 * @FilePath: \project\src\api\acl\user\index.ts
 */
import request from "@/utils/request";
import { RoleData, RoleListResponse, UserInfo, UserListResponse } from "./type";

enum API {
  GETUSERLIST_URL = '/admin/acl/user/', // 获取用户list
  ADDUSER_URL = '/admin/acl/user/save', // 增加用户
  EDITUSER_URL = '/admin/acl/user/update', // 修改用户
  GETROLELIST_URL = '/admin/acl/user/toAssign/', // 获取角色list
  ADDROLE_URL = '/admin/acl/user/doAssignRole',  // 分配角色
  DELETEUSER_URL = '/admin/acl/user/remove/',  // 删除用户
  DELETEUSERLIST_URL = '/admin/acl/user/batchRemove',  // 批量删除用户
}

// 用户列表
export const reqUserList = (page:number, limit:number, username:string) => request.get<any, UserListResponse>(API.GETUSERLIST_URL+`${page}/${limit}/?username=${username}`)
// 编辑和添加用户
export const reqAddEditUser = (data:UserInfo) => {
  if(data.id) {
    return request.put<any, any>(API.EDITUSER_URL,data)
  } else {
    return request.post<any, any>(API.ADDUSER_URL,data)
  }
}
// 获取角色
export const reqRoleList = (id:number) => request.get<any, RoleListResponse>(API.GETROLELIST_URL+id)
export const reqAddRole = (data:RoleData) => request.post<any, any>(API.ADDROLE_URL, data)
export const reqDeleteUser = (id:number) => request.delete<any, any>(API.DELETEUSER_URL+id)
export const reqDeleteUserList = (idList:number[]) => request.delete<any, any>(API.DELETEUSERLIST_URL, {data:idList})